import org.apache.spark.{SparkConf, SparkContext}

/**
 * ClassName: Homework4 <br/>
 * Description: <br/>
 * date: 2021/7/11 14:58<br/>
 *
 * @author Hesion<br/>
 * @version
 * @since JDK 1.8
 */
// 标签点
case class LabelPoint(label: String, point: Array[Double])
object Homework4 {
  def main(args: Array[String]): Unit = {
    //题目：使用鸢尾花数据集实现KNN算法
    val conf = new SparkConf().setAppName("Homework4").setMaster("local")
    val sc = new SparkContext(conf)
    sc.setLogLevel("warn")


    val k = 9
    sc.textFile("data/iris.csv")
      .map(line => {
        val fields = line.split(",")
        if (fields.length == 5)
           LabelPoint(fields.last,fields.init.tail.map(_.toDouble))
        else
          LabelPoint(fields.last, fields.init.tail.map(_.toDouble))
      })


    sc.stop()
  }
}
